package com.cskaoyan.controller;

import com.cskaoyan.bean.market.Keyword;
import com.cskaoyan.service.goods.GoodsService;
import com.cskaoyan.service.wxfree.WxSearchService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.goods.*;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * description:微信小程序的请求url的商品模块的controller层业务，主要功能有:
 *
 * wx/goods/count 商品总数
 * wx/goods/list 商品列表
 * wx/goods/category 商品分类数据，（当前分类，父类分类，子类分类）
 * wx/goods/detail 商品详情
 * wx/goods/related 商品详情页的关联商品，自定义逻辑（根据关键字或name查询，并且根据热门实现大家都在看的要求）
 *
 * author:houzhitao@139.com
 */
@RestController
@RequestMapping("wx")
public class WxGoodsController {
    private ObjectMapper objectMapper =new ObjectMapper();

    {
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    }
    @Autowired
    GoodsService goodsService;
    @Autowired
    WxSearchService wxSearchService;

    @RequestMapping("goods/count")
    public BaseRespVo countGoods(){
        WxGoodsCountVo countVo = goodsService.countGoods();
        return BaseRespVo.ok(countVo);
    }

    @RequestMapping("goods/list")
    public BaseRespVo goodsList(String Keyword,Integer categoryId,Integer page,Integer size){
        WxGoodsListVo wxGoodsListVo =  goodsService.wxQueryGoodsList(categoryId,page,size);
        wxSearchService.insertHistory(Keyword);
        return BaseRespVo.ok(wxGoodsListVo);
    }

    @RequestMapping("goods/category")
    public BaseRespVo goodsCategory(Integer id){
        WxGoodsCategoryVo categoryVo = goodsService.wxQueryGoodsCategory(id);
        return BaseRespVo.ok(categoryVo);
    }

    @RequestMapping("goods/detail")
    public BaseRespVo goodsDetail(Integer id){
        WxGoodsDetailVo wxGoodsDetailVo = goodsService.wxGoodsDetail(id);
        return BaseRespVo.ok(wxGoodsDetailVo);
    }

    @RequestMapping("goods/related")
    public BaseRespVo goodsRelated(Integer id){
        WxGoodsRelatedVo wxGoodsRelatedVo = goodsService.goodsRelated(id);
        return BaseRespVo.ok(wxGoodsRelatedVo);
    }

}
